home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
NOTIFY_M
/
STARTUPE.C
next >
Wrap
Text File
|
1992-07-19
|
3KB
|
152 lines
/**-------------------------------------------------------------------------
**
** Include Files
**
**/
#include "StartupError.h"
/**-------------------------------------------------------------------------
**
** Private Macros
**
**/
/**
T_NMInstall and T_Unimplemented are Mac toolbox trap numbers used to
test for the existence of the Notification Manager.
**/
#define T_NMInstall (0xA05E)
#define T_Unimplemented (0xA89F)
/**
STARTUP_ERROR_STR_ is the resource ID of the STR# containing the
error message corresponding to the error number passed to
StartupError().
RESPONSE_RESP is the resource ID of the RESP code resource compiled
separately and stuck in your INIT's resources.
**/
#define STARTUP_ERROR_STR_ (128)
#define RESPONSE_RESP (128)
/***************************************************************************
***
*** void StartupError(int errorNumber);
***
*** When your INIT runs into a problem, clean things up, show the X'ed
*** version of your icon and call StartupError() with an error number
*** corresponding to the message you want displayed.
***
*** History:
*** jhh 18 jun 90 -- response to news posting
*** pls 09 sep 91 -- minor change for C 4 & 5 compatibility
***
***/
void
StartupError(int errorNumber)
{
register NMRec *note;
register Handle responseCode;
register long size;
register THz svZone;
Str255 errorText;
/**
Make sure we've got a Notification Manager.
**/
if (NGetTrapAddress(T_NMInstall, OSTrap) !=
NGetTrapAddress(T_Unimplemented, ToolTrap)) {
/**
All of the memory we allocate from here on out is in the System
Heap. First create a Notification Manager record and fill it in.
Note that you can expand this notification method with sounds and
icons by adding the appropriate code. See the Notification
Manager technote #184 for details.
**/
svZone = TheZone;
TheZone = SysZone;
note = (NMRec *)NewPtrClear(sizeof(NMRec));
if (!note)
goto exit;
note->qType = nmType;
note->nmSound = (Handle)-1;
/**
Get the error message corresponding to the error number given.
For maximum performance, the STR# resource should be tagged
"Preload" and not "System Heap". This way, you can be sure
the messages will be there even if memory space is the cause of
the error.
We create a pointer in the System Heap just big enough for the
string and copy the string into it. Point the NM record at this
string.
**/
GetIndString(errorText, STARTUP_ERROR_STR_, errorNumber);
size = *(unsigned char *)errorText;
note->nmStr = (StringPtr)NewPtr(size);
if (!note->nmStr) {
DisposPtr(note);
goto exit;
}
BlockMove(errorText, note->nmStr, size);
/**
The response procedure also must be in a pointer in the System
Heap. You need to include the compiled code resource in your
INIT's resources of type 'RESP'.
Create a pointer just big enough for it and point the NM record
at it, also.
**/
responseCode = GetResource('RESP', RESPONSE_RESP);
if (!responseCode) {
DisposPtr(note->nmStr);
DisposPtr(note);
goto exit;
}
size = GetHandleSize(responseCode);
note->nmResp = (ProcPtr)NewPtr(size);
if (!note->nmResp) {
DisposPtr(note->nmStr);
DisposPtr(note);
goto exit;
}
BlockMove(*responseCode, note->nmResp, size);
/**
Now post the note. As soon as startup is complete, the NM
will display the note for the user's edification. Hurrah.
**/
NMInstall(note);
exit:
TheZone = svZone;
}
}